import 'package:flutter/material.dart';
import 'package:rc_widget/rc_widget.dart';

import 'package:flutter_study/widgets/public/themes/index.dart';

class AppRadio<T> extends StatelessWidget {
  const AppRadio(
      {super.key,
      required this.label,
      required this.value,
      required this.checked,
      this.labelStyle,
      this.iconSize,
      this.onChanged});

  final String label;
  final T value;
  final bool checked;
  final TextStyle? labelStyle;
  final double? iconSize;
  final ValueChanged<T>? onChanged;

  @override
  Widget build(BuildContext context) {
   return RcGestureDetector(
    onTap: ()=>onChanged?.call(value),
    child: Row(children: [
      _buildIcon(),
      AppGap.w8,
      _buildlable(),
    ],),
   );
  }
  
 Widget _buildIcon() {
  final icon = checked ? 'icon-xz' : 'icon-wxz';

   return Image.asset(
      'assets/images/public/$icon.webp',
      width: iconSize ?? 32.w,
      height: iconSize ?? 32.h,
      fit: BoxFit.contain,
    );
 }
  
 Widget _buildlable() {
  return Text(label, style: labelStyle ?? AppThemes.of().w400Text128);
 }
}
